var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
    })(e, t);
}, function(e, t) {
    function n() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, 
    new n());
}), a = this && this.__decorate || function(e, t, o, n) {
    var i, l = arguments.length, s = l < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, o) : n;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, o, n); else for (var c = e.length - 1; 0 <= c; c--) (i = e[c]) && (s = (l < 3 ? i(s) : 3 < l ? i(t, o, s) : i(t, o)) || s);
    return 3 < l && s && Object.defineProperty(t, o, s), s;
};

Object.defineProperty(n, "__esModule", {
    value: !0
}), n.HBCombine2Checked = void 0;

var r = e("HBCombine2ToggleView"), s = e("Global"), c = e("PrefabView"), l = e("AudioManager"), d = e("GameConfig"), u = e("GameData"), p = e("WebManager"), h = e("LoadManager"), f = e("UIManager"), g = cc._decorator, m = g.ccclass, y = g.property, v = function() {};

n.HBCombine2Checked = v;

var w = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.show = null, e.light = null, e.sprite = null, e.skeleton = null, e.scrollView = null, 
        e.tipsLabel = null, e.priceLabel = null, e.togglePrefab = null, e.toggleList = [], 
        e.checkedList = [], e.diamond = 500, e.spritePool = new cc.NodePool(), e;
    }
    return i(e, t), e.prototype.onLoad = function() {
        this.node.on("toggle", this.onToggle, this);
    }, e.prototype.onDestroy = function() {
        this.node.off("toggle", this.onToggle, this), t.prototype.onDestroy.call(this);
    }, e.prototype.onClickCombine = function() {
        var o = this;
        l.default.getInstance().playAudio("按钮2"), 0 == this.getEmptyChecked().length && (p.default.getInstance().sentLog("点击分红枪合成界面合成按键"), 
        u.GD.diamond < this.diamond ? s.G.platform != s.Platform.XiaoDu ? f.default.getInstance().loadPopPnl("diamond", {
            num: 100,
            view: this
        }) : f.default.getInstance().showToast({
            str: "钻石不足"
        }) : (u.GD.diamond -= this.diamond, this.checkedList.forEach(function(e) {
            e.toggle.item.box ? e.toggle.item.box.removeItem() : e.toggle.item.clear();
            var t = o.toggleList.indexOf(e.toggle);
            -1 < t && o.toggleList.splice(t, 1), e.toggle.node.destroy(), o.clearChecked(e);
        }), p.default.getInstance().lotteryGoldGun({
            success: function(e) {
                var t, o, n = f.default.getInstance().getPnl("start");
                0 == e.data.code ? (null === (o = null === (t = GA.PA) || void 0 === t ? void 0 : t.showToast) || void 0 === o || o.call(t, {
                    title: "合成黄金狙击成功",
                    icon: "none"
                }), 0 < (o = n.boxs.filter(function(e) {
                    return e.isEmpty();
                })).length ? n.appendItem(2002, o[0]) : n.appendEquip(2002), f.default.getInstance().loadPnl("hbCombineSuccess")) : (null === (o = null === (t = GA.PA) || void 0 === t ? void 0 : t.showToast) || void 0 === o || o.call(t, {
                    title: "合成黄金狙击失败",
                    icon: "none"
                }), f.default.getInstance().loadPnl("hbCombineFail")), n.updateMatrix();
            }
        })));
    }, e.prototype.onClickBack = function() {
        l.default.getInstance().playAudio("按钮2"), p.default.getInstance().sentLog("点击分红枪合成界面返回按键"), 
        this.hidePnl();
    }, e.prototype.onClickShareDraw = function() {
        l.default.getInstance().playAudio("按钮2"), p.default.getInstance().sentLog("点击分红枪合成界面查看详情按键"), 
        f.default.getInstance().loadPnl("hbShareDraw");
    }, e.prototype.onToggle = function(e) {
        var t, o;
        e.target instanceof cc.Node && ((t = e.target.getComponent(r.default)) && (l.default.getInstance().playAudio("点击合成材料音效"), 
        t.isChecked ? 0 < (e = this.getEmptyChecked()).length ? this.switchChecked(t, e[0]) : ((o = this.checkedList[this.checkedList.length - 1].toggle) && o.switchCheck(), 
        this.switchChecked(t, this.checkedList[this.checkedList.length - 1])) : 0 < (o = this.checkedList.filter(function(e) {
            return e.toggle == t;
        })).length && this.switchChecked(t, o[0])));
    }, e.prototype.start = function() {
        l.default.getInstance().playAudio("触发合成界面音效"), h.default.getInstance().loadSpriteFrame({
            url: "image/arm_draw/" + d.GC.maxDrawGunIdx,
            sprite: this.sprite
        }), this.init();
    }, e.prototype.init = function() {
        var e = this;
        this.tipsLabel.string = "2把" + s.G.gunModelList.length + "级武器有一定几率合成黄金武器；\n无论是否成功都将消耗2把" + s.G.gunModelList.length + "级武器;";
        var t = f.default.getInstance().getPnl("start").boxs.filter(function(e) {
            return e.item && e.item.rank == s.G.gunModelList.length - 1;
        }).map(function(e) {
            return e.item;
        });
        if (0 < t.length) for (var o = 0; o < t.length; o++) this.appendToggle(t[o]);
        cc.tween(this.light).repeatForever(cc.tween().by(2, {
            angle: 60
        })).start(), this.skeleton.setAnimation(0, "animation1", !1), this.skeleton.setEventListener(function() {
            e.skeleton.setEventListener(null), e.show.active = !0, e.show.opacity = 0, cc.tween(e.show).to(2 / 15, {
                opacity: 255
            }).start();
        }), this.skeleton.setCompleteListener(function() {
            e.skeleton.setCompleteListener(null), e.skeleton.setAnimation(0, "animation2", !0);
        }), this.addChecked(this.skeleton.findBone("quan1")), this.addChecked(this.skeleton.findBone("quan2"));
    }, e.prototype.appendToggle = function(e) {
        var t = cc.instantiate(this.togglePrefab), o = t.getComponent(r.default);
        o && (o.init(e), t.parent = this.scrollView.content, this.toggleList.push(o));
    }, e.prototype.reomveToggle = function(e) {
        e < this.toggleList.length && this.toggleList.splice(e, 1)[0].node.destroy();
    }, e.prototype.addChecked = function(e) {
        var t;
        e && ((t = new v()).bone = e, this.checkedList.push(t));
    }, e.prototype.switchChecked = function(e, t) {
        e.isChecked ? (t.toggle = e, t.sprite || (t.sprite = this.getSprite().getComponent(cc.Sprite)), 
        cc.Tween.stopAllByTarget(t.sprite.node), t.sprite.node.scale = .5, t.sprite.node.setPosition(this.node.convertToNodeSpaceAR(t.toggle.node.convertToWorldSpaceAR(cc.Vec2.ZERO))), 
        t.sprite.node.parent = this.node, cc.tween(t.sprite.node).to(.2, {
            scale: .7,
            position: cc.v3(t.bone.worldX + this.skeleton.node.x, t.bone.worldY + this.skeleton.node.y - 5)
        }).start()) : this.clearChecked(t);
    }, e.prototype.clearChecked = function(e) {
        e.toggle && (e.toggle.isChecked && e.toggle.switchCheck(), e.toggle = null), e.sprite && (this.spritePool.put(e.sprite.node), 
        e.sprite = null);
    }, e.prototype.getEmptyChecked = function() {
        return this.checkedList.filter(function(e) {
            return !e.toggle;
        });
    }, e.prototype.getSprite = function() {
        if (0 < this.spritePool.size()) return this.spritePool.get();
        var e = new cc.Node().addComponent(cc.Sprite);
        return h.default.getInstance().loadSpriteFrame({
            url: "image/arm/" + (s.G.gunModelList.length - 1),
            sprite: e
        }), e.node;
    }, a([ y(cc.Node) ], e.prototype, "show", void 0), a([ y(cc.Node) ], e.prototype, "light", void 0), 
    a([ y(cc.Sprite) ], e.prototype, "sprite", void 0), a([ y(sp.Skeleton) ], e.prototype, "skeleton", void 0), 
    a([ y(cc.ScrollView) ], e.prototype, "scrollView", void 0), a([ y(cc.Label) ], e.prototype, "tipsLabel", void 0), 
    a([ y(cc.Label) ], e.prototype, "priceLabel", void 0), a([ y(cc.Prefab) ], e.prototype, "togglePrefab", void 0), 
    a([ m ], e);
}(c.default);

n.default = w;